<?php
require_once("./include/appmain.php");

if($_POST['action'] == 'create'){
	$fail = false;
	
	$form = array();
	$form['user_name'] = $_POST['user_name'];
	$form['user_pass'] = $_POST['user_pass'];
	$form['user_email'] = $_POST['user_email'] ;
	
	
	if(strlen($form['user_name'])<1){
		$errorfield['user_name'] = true;
		$message['form_user_name_empty'] = true;
		$fail = true;
	}
	
	if(strlen($form['user_pass'])<1){
		$errorfield['user_pass'] = true;
		$message['form_user_pass_empty'] = true;
		$fail = true;
	}elseif($form['user_pass'] != $_POST['retype_pass']){
		$errorfield['user_pass'] = true;
		$errorfield['retype_pass'] = true;
		$message['form_user_retype_pass_incorrect'] = true;
		$fail = true;
	}
	
	
	if(strlen($form['user_email'])<1){
		$errorfield['user_email'] = true;
		$message['form_user_email_empty'] = true;
		$fail = true;
	}elseif(!ls_email_format($form['user_email'])){
		$errorfield['user_email'] = true;
		$message['form_user_email_format_incorrect'] = true;
		$fail = true;
	}
	$option = array(
		'role'=>$Config['default_user_role'],
		'status'=>$Config['default_user_status'],
		'active'=>$Config['default_user_active']
	);
	if(!$fail){
		$result = sugm_user_create($form,$option);
		if($result == SUGM_USER_CREATE_COMPLETE){
			$message ['user_create_complete'] = true;
		}elseif($result == SUGM_USER_CREATE_NEED_CONFIRM){
			$message ['user_create_need_confirm'] = true;
		}elseif($result == SUGM_USER_CREATE_NEED_ACTIVE){
			$message ['user_create_need_active'] = true;
		}elseif($result == SUGM_USER_CREATE_EMAIL_EXIST){
			$message ['user_create_email_exist'] = true;
		}elseif($result == SUGM_USER_CREATE_NAME_EXIST){
			$message ['user_create_name_exist'] = true;
		}else{
			$message ['user_create_unknow'] = true;
		}
	}
}


?>